﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    $(function () {
        getItemList();
    })
    function getItemList() {
        $.ajax({
            url: "/MiniSite/SiteActivity/GetItemListJson",
            dataType: "json",
            async: false,
            success: function (data) {
                gridList(data);
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest);
                console.log(textStatus);
                console.log(errorThrown);
            }
        });
    }
    function gridList(ItemList) {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/MiniSite/SiteActivity/GetGridJson",
            height: $(window).height() - 96,
            colModel: [
                { label: '编号', name: 'F_Id', hidden: true },
                { label: '客户编号', name: 'F_CustomerId', hidden: true},
                //{ label: '场地或空间编号', name: 'F_SiteId', width: 100, align: 'left' },
                //{ label: '场地或空间编号', name: 'F_SpaceId', width: 100, align: 'left' },
                //{ label: '订单编号', name: 'F_OrderId', width: 100, align: 'left' },
                { label: '活动标题', name: 'F_Title', width: 180, align: 'left' },
                { label: '活动主题', name: 'F_Subject', width: 180, align: 'left' },
                //{ label: '活动内容', name: 'F_Content', width: 100, align: 'left' },
                {
                    label: '社区对象', name: 'F_CommunityObjectType', width: 80, align: 'left',
                    formatter: function (cellvalue) {
                        return FMDictionaries(ItemList.CommunityObject, cellvalue);
                    } },
                { label: '金额', name: 'F_Price', width: 60, align: 'left' },
                {
                    label: '消费', name: 'F_ConsumeType', width: 60, align: 'left',
                    formatter: function (cellvalue) {
                        return FMDictionaries(ItemList.Consume, cellvalue);
                    } },
                {
                    label: '出行', name: 'F_TripType', width: 60, align: 'left',
                    formatter: function (cellvalue) {
                        return FMDictionaries(ItemList.Trip, cellvalue);
                    }},
                {
                    label: '开始时间', name: 'F_StartTime', width: 150, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
                },
                {
                    label: '活动类型', name: 'F_ActivityType', width: 60, align: 'left',
                    formatter: function (cellvalue) {
                        switch (cellvalue) {
                            case 1:
                                return "场地方发起";
                                break;
                            case 2:
                                return "平台发起";
                                break;
                            default:
                                return "";
                        }
                    }
                },
                {
                    //状态 0.活动初始; 1.未开始; 2.进行中; 3.已结束; 4.待评价; 5.已完结;6.待上架
                    label: '状态', name: 'F_Status', width: 80, align: 'left',
                    formatter: function (cellvalue) {
                        switch (cellvalue) {
                            case 0:
                                return "活动初始";
                                break;
                            case 1:
                                return "未开始";
                                break;
                            case 2:
                                return "进行中";
                                break;
                            case 3:
                                return "已结束";
                                break;
                            case 4:
                                return "待评价";
                                break;
                            case 5:
                                return "已完结";
                                break;
                            case 6:
                                return "待上架";
                                break;
                            default:
                                return "已下架";
                        }
                    }
                },
                {
                    label: '活动地址', name: 'F_Address', width: 180, align: 'left'
                },
                {
                    label: '指定人员', name: 'F_DesignatedCustomer', width: 250, align: 'left',
                    formatter: function (cellvalue) {
                        if (cellvalue == null)
                            return "";
                        else
                            return FMDictionaries(ItemList.DesignatedCustomer, cellvalue);
                    }
                },
                { label: '发起人', name: 'F_Initiator', width: 80, align: 'left' }, 
                { label: '发起人手机号', name: 'F_Phone', width: 100, align: 'left' },
                {
                    label: '公开活动', name: 'F_IsPublic', width: 80, align: 'left',
                    formatter: function (cellvalue) {
                        if (cellvalue) {
                            return "公开";
                        }
                        else {
                            return "不公开";
                        }
                    }
                },
                //{ label: '排序', name: 'F_Sort', width: 100, align: 'left' },
                //{
                //    label: '示例', name: 'SampleAttr', width: 230, align: 'left',
                //    formatter: function (cellvalue, options, rowObject) {
                //        return cellvalue + ";" + rowObject.F_IPAddressName;
                //    }
                //}
            ],
            pager: "#gridPager",
            sortname: 'F_Id desc',
            viewrecords: true
        });

        $("#state_activity_horizon a.btn-default").click(function () {
            $("#state_activity_horizon a.btn-default").removeClass("active");
            $(this).addClass("active");
            $('#btn_search').trigger("click");
        });
        $("#btn_search").click(function () {
            var queryJsonSearch = {
                keyword: $("#txt_keyword").val(),
                F_Status: $("#state_activity_horizon a.active").attr('data-value'),
            }
            $gridList.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJsonSearch) },
            }).trigger('reloadGrid');
        });
    }
    function FMDictionaries(state, cellvalue) {
        if (cellvalue != undefined) {
            for (var i = 0; i < state.length; i++) {
                if (state[i].F_ItemCode.toString() == cellvalue.toString()) {
                    cellvalue = state[i].F_ItemName;
                    break;
                }
            }
        } else { cellvalue = ""; }
        return cellvalue;
    }
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增活动",
            url: "/MiniSite/SiteActivity/Form",
            width: "1100px",
            height: "800px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_UpState(state) {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.ajax({
            url: "/MiniSite/SiteActivity/UpStateForm",
            dataType: "json",
            async: false,
            success: function (data) {
                gridList(data);
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest);
                console.log(textStatus);
                console.log(errorThrown);
            }
        });
        $.submitForm({
            url: "/MiniSite/SiteActivity/UpStateForm?keyValue=" + keyValue,
            param: { F_Status: state },
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }

    function btn_edit() {
        var F_ActivityType = $("#gridList").jqGridRowValue().F_ActivityType;
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        if (F_ActivityType ==1 )
        {
            alert("该活动由客户发起，不可编辑。")
            return;
        }
        $.modalOpen({
            id: "Form",
            title: "修改活动",
            url: "/MiniSite/SiteActivity/Form?keyValue=" + keyValue,
            width: "1100px",
            height: "800px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_delete() {
        var F_ActivityType = $("#gridList").jqGridRowValue().F_ActivityType;
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        if (F_ActivityType == 1) {
            alert("该活动由客户发起，不可删除。")
            return;
        }
        $.deleteForm({
            url: "/MiniSite/SiteActivity/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().F_Id },
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_photos() {

        var photoable_id = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "Photos",
            title: "图片管理",
            url: "/SiteManage/Photos/Photos?photoable_type=SiteActivity&photoable_id=" + photoable_id,
            width: "800px",
            height: "620px",
            btn: null
        });
    }

</script>
<style type="text/css">
    .ui-jqgrid tr.jqgrow td {
        white-space: normal !important;
        height: auto;
        vertical-align: text-top;
        padding-top: 2px;
    }
    th.ui-th-column div {
        white-space: normal !important;
        height: auto !important;
        padding: 0px;
        font-weight:bold;
    }
</style>
<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-eraser"></i>添加按钮</a>
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
                <li><a id="NF-edit" authorize="yes" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改活动</a></li>
                <li><a id="NF-delete" authorize="yes" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除活动</a></li>
                <li><a id="NF-photos" authorize="yes" onclick="btn_photos()"><i class="fa fa-picture-o"></i>图片管理</a></li>
                <li><a id="NF-UpState-S" authorize="yes" onclick="btn_UpState('0')"><i class="fa fa-picture-o"></i>上架</a></li>
                <li><a id="NF-UpState-X" authorize="yes" onclick="btn_UpState('7')"><i class="fa fa-picture-o"></i>下架</a></li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div id="state_activity_horizon" class="btn-group">
                        <a class="btn btn-default active" data-value="0">活动初始</a>
                        <a class="btn btn-default" data-value="1">未开始</a>
                        <a class="btn btn-default" data-value="2">进行中</a>
                        <a class="btn btn-default" data-value="3">已结束</a>
                        <a class="btn btn-default" data-value="4">待评价</a>
                        <a class="btn btn-default" data-value="5">已完结</a>
                        <a class="btn btn-default" data-value="6">待上架</a>
                        <a class="btn btn-default" data-value="7">已下架</a>
                    </div>
                </td>
                <td>
                    <div class="input-group" style="margin-left:20px;">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
                @*<td class="formValue">
            状态 0.活动初始; 1.未开始; 2.进行中; 3.已结束; 4.待评价; 5.已完结;6.待上架;7:已下架
            <select id="F_Status" name="F_Status" class="form-control">
                <option value="">--请选择活动状态--</option>
                <option value="0">活动初始</option>
                <option value="1">未开始</option>
                <option value="2">进行中</option>
                <option value="3">已结束</option>
                <option value="4">待评价</option>
                <option value="5">已完结</option>
                <option value="6">待上架</option>
            </select>
        </td>*@
            </tr>
        </table>
    </div>
</div>

<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>


